Repository navigation
Conversation
rskj keeps its flat unitrie in RocksDB's default column family, keyed by node
hash; rustock keeps the same bytes in a trie_nodes column family. The import
between them is a straight key-to-value copy -- content-addressed nodes,
nothing transformed -- so the only real difference is which column family the
bytes live in, and an adapter is a thin reader.
Worth having because of what it unlocks. A range-scoped segment build
parallelises only when each range can seed from an archival pre-state;
without one it is a single sequential pass from genesis. Testnet's blocks are
imported but its state was deliberately not ("Skipping the trie phase: state
will be read from the source instead"), so it has 108 GB of rskj-format
unitrie and no rustock-format archive. This makes that snapshot usable as-is,
turning a sequential build into a parallel one and skipping a multi-hour
import.
It REFUSES a rustock store rather than opening one and answering None to every
hash. That failure is the reason this check exists: a default-family reader
pointed at a rustock store finds nothing and reports every node absent, which
is indistinguishable from a pruned archive, and has already been taken for a
real result once (see rskj_root_probe's note).
Tuned for scattered point lookups as rskj_import::open_source_random is --
every table open, index and filter blocks cached -- because the opposite
setting, right for a sequential scan, measured ~83 reads/s on a comparable
random workload.
Three unit tests on a synthetic store, plus an ignored test against a real
snapshot: testnet #2,000,000's state root resolves to a 72-octet node from the
real 108 GB unitrie, which is the part that would be embarrassing to get wrong.
Refs #411
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…t ETA Three things were hardcoded to mainnet, and the third is the dangerous one: - ChainConfig::mainnet() for the genesis allocation; - UNITRIE_FROM = 1_591_000, mainnet's RSKIP-126 height; - RskHardforkConfig::mainnet() for the consensus rules. Executing testnet blocks under mainnet rules would compute a different state root for every block straddling an activation the two ladders place differently, which on testnet is most of them -- orchid and wasabi100 are both at height 0 there. The UNITRIE_FROM default is subtler and would have been worse to miss. Because wasabi100 is at height 0 on testnet, its Unitrie starts at genesis and there is no Orchid era. Left at the mainnet value, every testnet block below #1,591,000 would have looked for a baseline that does not exist, found no expected root, and been built WITHOUT VERIFICATION -- "built out of state nothing has checked", in the tool's own warning. That is 77% of the range below testnet iris300. So: --network mainnet|testnet selects all three, with --unitrie-from N to override the height explicitly. The archive may now be a rustock store or an rskj one, chosen by inspecting the column families rather than by a flag. A flag would be silent when wrong: a default-family reader on a rustock store reports every node absent, which looks exactly like a pruned archive. Progress gains a percentage, a rate and an ETA, printed as a readable line as well as written to the progress file, so a reader does not have to divide two other fields to learn whether a build will finish tonight. Refs #411 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The fallback was opened inside the per-segment loop, so a 77-segment run opened the same 131 GB read-only database 77 times. Measured at 6.9s per open on a warm page cache and 15-21s cold, that was roughly two thirds of the run spent reopening one store. It is read-only and identical for every segment, so it is shared behind an Arc and opened before the loop. The open is timed and reported, because an estimate that turns out to be three times the measured figure is worth replacing with the measurement. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three changes that together make a testnet segment set buildable, plus a measured speedup to the repair tool.
Read an rskj unitrie directly
rskj keeps its flat unitrie in RocksDB's default column family; rustock keeps the same bytes in
trie_nodes. The import between them is a straight key-to-value copy — content-addressed nodes, nothing transformed — so an adapter is a thin reader.What it unlocks: a range-scoped build parallelises only when each range can seed from an archival pre-state. Testnet's blocks are imported but its state deliberately was not (
Skipping the trie phase: state will be read from the source instead), so it has 108 GB of rskj-format unitrie and no rustock archive. Without this, a testnet build is one sequential pass from genesis. With it, the snapshot is usable as-is — parallel ranges, and no multi-hour import.It refuses a rustock store rather than opening one and answering
Noneto every hash. That is the whole reason the check exists: a default-family reader on a rustock store finds nothing and reports every node absent, indistinguishable from a pruned archive, and that has already been taken for a real result once.Three unit tests, plus an ignored one against the real snapshot: testnet #2,000,000's state root resolves to a 72-octet node from the real 108 GB unitrie.
build_segments --network mainnet|testnetThree things were hardcoded to mainnet, and the third is the dangerous one:
ChainConfig::mainnet()for the genesis allocationUNITRIE_FROM = 1_591_000, mainnet's RSKIP-126 heightRskHardforkConfig::mainnet()for the consensus rulesExecuting testnet blocks under mainnet rules computes a different state root for every block straddling an activation the ladders place differently — on testnet, most of them, since
orchidandwasabi100are both at height 0.The
UNITRIE_FROMdefault would have been worse to miss. Becausewasabi100is at height 0 on testnet, its Unitrie starts at genesis and there is no Orchid era. Left at the mainnet value, every testnet block below #1,591,000 would have looked for a baseline that does not exist, found no expected root, and been built without verification — "built out of state nothing has checked", in the tool's own warning. That is 77% of the range below testnet iris300. A segment set that looks built and was never checked is worse than one that fails loudly.The archive may now be either format, chosen by inspecting column families rather than by a flag — a flag is silent when wrong, for the reason above.
Progress gains a percentage, a rate and an ETA, printed as a readable line as well as written to the progress file.
repair_segments: open the archive onceThe fallback was opened inside the per-segment loop, so a 77-segment run opened the same 131 GB read-only database 77 times. Measured at 6.9 s warm and 15–21 s cold, that was roughly two-thirds of the run. It is read-only and identical every iteration, so it is shared behind an
Arcand opened before the loop, with the open timed and reported.Verification
Workspace typechecks with examples and tests, zero warnings;
rustock-storagesuite passes including the three new adapter tests.Beyond unit tests, the repaired mainnet segment set was re-executed by rskj from the live segment directory over blocks 3,810,000–3,814,999 — a range straddling #3,812,411, the block whose missing node aborted a rustock replay before the repair:
No missing nodes, no state-root mismatches. (Note for anyone repeating it: rskj needs JDK 17; under Java 25 gradle fails immediately with
Unsupported class file major version 69.)Refs #411
🤖 Generated with Claude Code